#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 测试环境: python2.7
# 安装requests依赖 => pip install requests/ easy_install requests

# 导入requests依赖
import requests
import json
import sys

reload(sys)
sys.setdefaultencoding("utf-8")

def apishop_send_request(method, url, params=None, headers=None):
   '''
   转发请求到目的主机
   @param method str 请求方法
   @param url str 请求地址
   @param params dict 请求参数
   @param headers dict 请求头
   '''
   method = str.upper(method)
   if method == "POST":
       return requests.post(url=url, data=params, headers=headers)
   elif method == "GET":
       return requests.get(url=url, params=params, headers=headers)
   else:
       return None

method = "POST"
url = "https://api.apishop.net/common/plantFamily/queryPlantListByKeyword"
headers = None
params = {
   "apiKey" : "vBqlVXl40a93061d67a24f7f2e03e64b1a561310f8d945b", #apiKey
   "page" : "1", #页码（默认为1）
   "pageSize" : "30", #当前页面植物数量（默认为30）
   "keyword" : "羊", #关键字
}
result = apishop_send_request(method=method, url=url, params=params, headers=headers)
if result:
   body = result.text
   response = json.loads(body)
   status_code = response["statusCode"]
   if (status_code == "000000"):
       # 状态码为000000, 说明请求成功
       print("请求成功：%s" % (body,))
   else:
       # 状态码非000000, 说明请求失败
       print("请求失败: %s" % (body,))
   else:
       # 返回内容异常，发送请求失败
       print("发送请求失败"")